#include "StdAfx.h"
#include "DrawKeelWall.h"

CDrawKeelWall::CDrawKeelWall(const AcDbObjectIdArray& wallIdAry)
{
	m_objWallIdAry = wallIdAry;
}

CDrawKeelWall::~CDrawKeelWall(void)
{
}

BOOL CDrawKeelWall::TzWall2HelpLine()
{

	for (int i = 0 ; i < m_objWallIdAry.length() ; ++i)
	{
		AcDbObjectPointer< AcDbCurve > pTzWall(m_objWallIdAry.at(i) , AcDb::kForRead);
		if (pTzWall.openStatus() != Acad::eOk)
		{
			continue;
		}
		AcGePoint3d ptStart , ptEnd;
		pTzWall->getStartPoint(ptStart);
		pTzWall->getEndPoint(ptEnd);
		AcDbLine* pLine = new AcDbLine(ptStart , ptEnd);
		AcadUtil::AddToDB(pLine , TRUE , ACDB_MODEL_SPACE , acdbCurDwg());
	}
	return TRUE;
}

BOOL CDrawKeelWall::DrawWallPmt()
{
	TzWall2HelpLine();
	
	DealWithWallCorner();
	return TRUE;
}

BOOL CDrawKeelWall::DealWithWallCorner()
{
	for (int i = 0 ; i < m_objWallIdAry.length() - 1; ++i)
	{
		AcDbObjectPointer< AcDbCurve > pTzWall(m_objWallIdAry.at(i) , AcDb::kForRead);
		if (pTzWall.openStatus() != Acad::eOk)
		{
			continue;
		}
		AcGePoint3d ptStart , ptEnd;
		pTzWall->getStartPoint(ptStart);
		pTzWall->getEndPoint(ptEnd);
		AcDbObjectIdArray objTempIdAryEndPtEqual;
		AcDbObjectIdArray objTempIdAryStartPtEqual;
		for (int j = i + 1 ; j < m_objWallIdAry.length() ; ++j)
		{
			AcDbObjectPointer< AcDbCurve > pTzWall(m_objWallIdAry.at(j) , AcDb::kForRead);
			if (pTzWall.openStatus() != Acad::eOk)
			{
				continue;
			}
			AcGePoint3d ptStartSecond , ptEndSecond;
			pTzWall->getStartPoint(ptStartSecond);
			pTzWall->getEndPoint(ptEndSecond);
			if (ptStart.isEqualTo(ptStartSecond) || ptStart.isEqualTo(ptEndSecond))
			{
				objTempIdAryStartPtEqual.append(m_objWallIdAry.at(j));
				AcDbCircle* pCircle = new AcDbCircle(ptStart , AcGeVector3d::kZAxis , 100);
				AcadUtil::AddToDB(pCircle , TRUE , ACDB_MODEL_SPACE , acdbCurDwg());
			}
			if (ptEnd.isEqualTo(ptStartSecond) || ptEnd.isEqualTo(ptEndSecond))
			{
				objTempIdAryEndPtEqual.append(m_objWallIdAry.at(j));
				AcDbCircle* pCircle = new AcDbCircle(ptEnd , AcGeVector3d::kZAxis , 100);
				AcadUtil::AddToDB(pCircle , TRUE , ACDB_MODEL_SPACE , acdbCurDwg());
			}
		}
		objTempIdAryStartPtEqual.append(m_objWallIdAry.at(i));
		objTempIdAryEndPtEqual.append(m_objWallIdAry.at(i));
	}
	return TRUE;
}
